/**
 * Copyright (C) gis consulting 2006
 * author: Gérald Fenoy
 *
 */

/**
 * The Rss Application
 */

System.require('View');

RssApplication=Class.create({
  id: 0,
  ListFeeds: View.extend(),
  ListNodes: View.extend(),
  run: function(){

      eval("RssApp"+this.id+"=new WindowControler(Array('RssApp"+this.id+"','RssApp'),Array(300,100),Array(350,50));");
      
      eval("desk.add(RssApp"+this.id+"Win);");
      
      eval("RssApp"+this.id+".execRequest('./modules/rss/Form.xml',Array());");


      var i=1;
      while(!document.getElementById('RssList')){i/10;i++}

      eval("RssListFeedsControler"+this.id+"=new OctoControler();");
      eval("RssListFeeds"+this.id+"=new RssApplication.ListFeeds({root: document.getElementById('RssList') });");
      eval("RssListFeedsControler"+this.id+".setView(RssListFeeds"+this.id+");");
      eval("RssListFeedsControler"+this.id+".execRequest('./modules/rss/ListLinkFromSite.php');");


      eval("RssListNodesControler"+this.id+"=new OctoControler();");
      eval("RssListNodes"+this.id+"=new RssApplication.ListNodes({root: document.getElementById('RssView') });");
      eval("RssListNodesControler"+this.id+".setView(RssListNodes"+this.id+");");
      eval("RssListNodesControler"+this.id+".execRequest('./modules/rss/RssReader.php');");

      
      this.id++;

    }

  });

RssApplication.ListNodes.define({
    
  root: "channel",

  rootValues: { 
    ct: "title",
    description: "description",
    ci: { src: "image.url", title: "image.title" }
  },

  rootElements: { 
    ct: "div",
    description: "div",
    ci: "img"
  },

  loop:"item",
  loopNode:"div",

  loopValues: { 
    cit: "title", 
    cil0: { href: "link" },
    cil1: { href: "link" },
    cieu: { src: 'enclosure["@url"]' },
    cid: "description",
    cip: "pubDate"
  },

  loopElements: { 
    cit: "div", 
    cil0: "a",
    cil1: "a",
    cieu: "img",
    cid: "div",
    cip: "span"
  },

  htmlValues: ["description","cid"],

  appUrl: "./modules/rss/RSSView.xml"

  });

RssApplication.ListFeeds.define({
  root: "result",
      
  rootValues: { },
      
  rootElements: { },
      
  loop:"link",
  loopNode:"div",
      
  loopValues: { 
    desc: "title",
    ref: { idx: "href"}
  },

  loopElements: { 
    desc: "span",
    ref: "div"
  },

  htmlValues: [],

  appUrl: "./modules/rss/RSSListFeeds.xml"

  });
